<%--
  Created by IntelliJ IDEA.
  User: 12088
  Date: 2023/7/26
  Time: 11:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>功能添加</title>
    <script src="js/jquery.js"></script>
    <link rel="stylesheet" href="js/layui/css/layui.css">
</head>
<body style="padding: 20px">



<form class="layui-form " action="">


    <div class="layui-form-item" >
        <label class="layui-form-label">功能编号</label>
        <div class="layui-input-block">
            <input id="funcId" type="text" class="layui-input" lay-verify="required" style="width: 200px"> </div>
    </div>

    <div class="layui-form-item" >
        <label class="layui-form-label" >功能名称</label>
        <div class="layui-input-block">
            <input id="funcName" type="text" class="layui-input" lay-verify="required" style="width: 200px"> </div>
    </div>

    <div class="layui-form-item" >
        <label class="layui-form-label">开发天数</label>
        <div class="layui-input-block">
            <input id="devDays" type="text" class="layui-input" lay-verify="required" style="width: 200px;"> </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">所属项目</label>
        <div class="layui-input-block" style="width: 200px;">
            <select name="project" lay-verify="required" lay-search="" id="prjId" lay-filter="prj_filter" >
                <option value="">请选择项目</option>
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">所属模块</label>
        <div class="layui-input-block" style="width: 200px;">
            <select name="mod" lay-verify="required" lay-search="" id="modId" >
                <option value="">---未选择项目---</option>
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-bg-blue" lay-submit lay-filter="save_filter">确认</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>

</form>

</body>
<script src="js/layui/layui.js" charset="utf-8"></script>
<script>

    layui.use('form', function () {
        var form = layui.form;
        form.render();
        $.ajax({
            url: "getAllProjectList",
            type: "GET",
            dataType: "json",
            success: function (result) {
                var list = result;    //返回的数据
                var project = document.getElementById("prjId"); //server为select定义的id
                for (var p in list) {
                    var option = document.createElement("option");  // 创建添加option属性
                    option.setAttribute("value", list[p].id); // 给option的value添加值
                    option.innerText = list[p].id + "  (" + list[p].proName + ")";     // 打印option对应的纯文本
                    project.appendChild(option);           //给select添加option子标签
                    form.render("select");            // 刷性select，显示出数据
                }
            }
        })


        form.on('select(prj_filter)', function (data) {
            $("#modId").empty();
            var prjId = data.value;
            if (prjId != "") {
                $.ajax({
                    url: "getModList",
                    dataType: "json",
                    type: "POST",
                    data: {prjId: prjId,page:1,limit:99999},
                    success: function (result) {
                        var list = result.data;    //返回的数据
                        var mod = document.getElementById("modId"); //server为select定义的id
                        for (var p in list) {
                            var option = document.createElement("option");  // 创建添加option属性
                            option.setAttribute("value", list[p].modId); // 给option的value添加值
                            option.innerText = list[p].modId + "  (" + list[p].modName + ")";     // 打印option对应的纯文本
                            mod.appendChild(option);           //给select添加option子标签
                            form.render("select");            // 刷性select，显示出数据
                        }
                    }
                });
            }
            else {
                var dj = "<option value=''>---未选择项目--</option>";
                $("#modId").html(dj);
                $("#modId").val('');
                form.render();
            }
            form.render("select");
        });


        form.on('submit(save_filter)', function(data){
            var index=parent.layer.getFrameIndex(window.name);
            window.parent.addFunc($("#funcId").val(),$("#funcName").val(),$("#devDays").val(),$("#modId").val(),$("#prjId").val());
            parent.layer.close(index);
            return false; // 阻止默认 form 跳转
        });

    })



















</script>



</html>
